<template>
    <div>
        <el-card>
            <el-form :model="tiYanForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-tiYanForm">
                <el-row>
                    <br>
                    <h4>体验金参数</h4>
                    <br>
                        <el-col :span="12">
                            <el-form-item label="体验金金额" prop="tiYan" required>
                                <el-input type="text" v-model="tiYanForm.tiYan" placeholder="请输入100-99999的整数"></el-input>
                            </el-form-item>
                            <el-form-item label="有效天数" prop="tyDate" required>
                                <el-input type="text" v-model="tiYanForm.tiYandate" placeholder="请输入0-365之间的整数，0则永久有效"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="每天发放量" prop="tiYannum" required>
                                <el-input type="text" v-model="tiYanForm.tiYannum" placeholder="请输入0-99999的整数，0则不限制"></el-input>
                            </el-form-item>
                            <el-form-item label="发放开关" prop="resource">
                                <el-radio label="0" v-model="tiYanForm.userType">注册送</el-radio>
                                <el-radio label="1" v-model="tiYanForm.userType">不发放</el-radio>
                            </el-form-item>
                        </el-col>
                </el-row>
                <el-row>
                    <br>
                    <h4>体验标信息</h4>
                    <br>
                    <el-col :span="12">
                        <el-form-item label="体验标标民" prop="tiYanname" required>
                            <el-input type="text" v-model="tiYanForm.tiYanname" placeholder="请输入名称"></el-input>
                        </el-form-item>
                        <el-form-item label="年利率" prop="Rate" required>
                            <el-input type="text" v-model="tiYanForm.Rate" placeholder="请输入1-24之间的数，保留2位小数"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="项目期限" prop="tiYantime" required>
                            <el-input type="text" v-model="tiYanForm.tiYantime" placeholder="请输入0-999的整数"></el-input>
                        </el-form-item>

                    </el-col>
                </el-row>
            </el-form>
        </el-card>
    </div>


</template>

<script>

    export default {
        name: "yunying1",
        data(){
            /* 判断体验金金额 */
            let tiYan = (rule,value,callback) => {
                let num = parseInt(value);

                if(value === ''){
                    callback(new Error('请输入100-99999的整数'));
                }else if (num > 99999 && num < 100){
                    callback(new Error('请输入正确的金额整数'));
                }else {
                    callback();
                }
            };

            /* 判断体验天数 */
            let tiYandate = (rule,value,callback) => {
                let tyDate = parseInt(value);

                if (value === ''){
                    callback(new Error('请输入0-365之间的整数，0则永久有效'))
                }else if (tyDate > 365 && tyDate < 0){
                    callback(new Error('请输入正确的有效天数'))
                }else {
                    callback();
                }
            };

            /* 判断每天发放量限制 */
            let tiYannum = (rule,value,callback) => {
                let tyNum = parseInt(value);

                if (value === ''){
                    callback(new Error('请输入0-99999之间的整数，0则不限制'))
                }else if (tyNum > 99999 && tyNum < 0){
                    callback(new Error('请输入正确发放量'))
                }else {
                    callback();
                }
            };

            /* 判断年利率 */
            let Rate = (rule,value,callback) => {
                let rate = parseFloat(value);

                if (value === ''){
                    callback(new Error('请输入1-24之间的数，保留两位小数'))
                }else if (rate >= 25 && rate < 1){
                    callback(new Error('请输入正确的利率'))
                }else {
                    callback();
                }
            };

            /* 判断体验标标名不能为空 */
            let tiYanname = (rule, value, callback) => {
                if (this.tiYanForm.tiYanname == '0' && value === '') {
                    callback(new Error('请输入名称'));
                } else {
                    callback();
                }
            };

            /* 判断项目期限为0-999的整数 */
            let tiYantime = (rule, value, callback) =>{
                let tyTime =  parseInt(value);

                if (value === ''){
                    callback(new Error('请输入0-999之间的整数'))
                }else if (tyTime > 999 && tyTime < 0){
                    callback(new Error('请输入正确的项目时间'))
                }else {
                    callback();
                }
            }
            return {
                tiYanForm:{
                    tiYan:'',
                    tiYandate:'',
                    tiYannum:'',
                    Rate:'',
                    tiYanname:'',
                    tiYantime:'',
                },
                rules: {
                    tiYan: [
                        { validator: tiYan, trigger: 'blur'}
                    ],
                    tiYandate: [
                        { validator: tiYandate, trigger: 'blur'}
                    ],
                    tiYannum: [
                        { validator: tiYannum, trigger: 'blur'}
                    ],
                    Rate: [
                        { validator: Rate, trigger: 'blur'}
                    ],
                    tiYanname: [
                        { validator: tiYanname, trigger: 'blur'}
                    ],
                    tiYantime: [
                        { validator: tiYantime, trigger: 'blur'}
                    ],
                },
            };
        },


    }

</script>


<style scoped>

</style>